<template>
  <div class="workInstructionLibrary flowCloumn h100">
    <div class="constentmain h100">
      <list-table-new v-bind="tableSetting" ref="klTable"></list-table-new>
    </div>
  </div>
</template>

<script>
import {
  getExperimentList,
  saveExperiment,
  deleteExperiment,
} from "@/api/equipmentLedger/electricalTestReport.js";
export default {
  data() {
    return {
      tableSetting: {
        pageConfig: {
          pageCode: "electricalTestReport",
          userId: this.$store.getters.userInfo.id,
        },
        selectionShow: false,
        searchObj: {
          searchMethod: (params, sortStr) => {
            this.getTableData(params, sortStr);
          },
          queryData: {
            page: 1,
            pageSize: 15,
          },
          searchArr: [
            {
              type: "organization",
              label: "所属单位",
              model: "deptName",
              idsStr: "deptId",
              placeholder: "请选择",
            },
            {
              type: "input",
              label: "标题",
              model: "title",
            },
            {
              type: "select",
              label: "状态",
              model: "status",
              option: this.$store.getters.dirtData("electricalTest_code"),
            },
            {
              type: "userOnly",
              label: "创建人",
              model: "createByName",
              idsStr: "createBy",
            },
            {
              type: "datetimerange",
              label: "试验日期",
              model: "createTimes",
            },
          ],
        },
        //过滤器的值
        filterFormData: {},
        //过滤器的默认值
        defaultFilterData: {},
        userCustomData: [],
        actionList: [
          {
            name: "新建",
            icon: "el-icon-plus",
            disabled: !this.$store.getters.isBtnAuth("add"), //控制按钮的禁用
            content: "未授权功能", //禁用提示内容
            method: (row) => {
              this.goDetailPage(row, "electricalTestReportDetails", "add");
            },
          },
        ],
        tableMethods: {
          //点击行的方法
          rowClick: (row) => {
            this.goDetailPage(row, "electricalTestReportDetails", "edit");
          },
        },
        column: [
          {
            label: "状态",
            prop: "status",
            sortable: "custom",
            formatter: (row) => {
              return this.$store.getters.fineDirtDataName(
                "electricalTest_code",
                row.status
              );
            },
          },
          {
            label: "标题",
            prop: "title",
            sortable: "custom",
          },
          {
            label: "所属单位",
            prop: "deptName",
            sortable: "custom",
          },
          {
            label: "当前节点",
            prop: "currNodeName",
            sortable: "custom",
          },
          {
            label: "当前处理人",
            prop: "currNodeUser",
            sortable: "custom",
            showTooltip: true,
          },
          {
            label: "创建人",
            prop: "createByName",
            sortable: "custom",
          },
          {
            label: "创建时间",
            prop: "createTime",
            sortable: "custom",
          },
        ],
      },
    };
  },
  created() {
    /* 添加监听事件 */
    window.addEventListener("storage", this.updateData);
  },
  beforeDestroy() {
    /* 删除监听事件 */
    window.removeEventListener("storage", this.updateData);
  },
  mounted() {
    this.$refs.klTable.getTableConfig();
  },
  methods: {
    //跳转到详情页
    goDetailPage(row, router, type) {
      const { href } = this.$router.resolve({
        name: router,
        query: {
          id: row ? row.id : "",
          pageType: type ? type : "",
          status: row ? row.status : "",
        },
      });
      window.open(href, "_blank");
    },
    //获取列表数据
    getTableData(params, sortStr) {
      const { createTimes, ...restParams } = params
      if(createTimes) {
        restParams.beginTime = createTimes[0]
        restParams.endTime = createTimes[1]
      }
      let queryData = Object.assign({}, restParams);
      if (sortStr.length > 0) {
        queryData.orders = sortStr;
      }
      getExperimentList(queryData).then((res) => {
        this.$set(this.tableSetting, "tableData", res.data.list);
        this.$set(this.tableSetting, "totalNumber", res.data.total);
      });
    },
  },
};
</script>

<style lang="less" scoped>
.workInstructionLibrary {
  padding: 20px;
  .constentmain {
    //margin-left: 10px;
  }
  .attachForm {
    margin-top: 0px !important;
  }
}
.flowCloumn {
  display: flex;
  flex-flow: column nowrap;
}
</style>
